package com.mxpio.webapp.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.mxpio.webapp.constant.ZeroOrOneConstants;
import com.mxpio.webapp.dto.ServerPackage;
import com.mxpio.webapp.dto.server.CpuDomain;
import com.mxpio.webapp.dto.server.MemoryDomain;
import com.mxpio.webapp.dto.server.NetDomain;
import com.mxpio.webapp.dto.server.OsDomain;
import com.mxpio.webapp.entity.*;
import com.mxpio.webapp.service.IMonitorServerService;
import com.mxpio.webapp.util.DataSizeUtil;
import com.mxpio.webapp.vo.MonitorServerVo;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.jpa.initiator.JpaUtilAble;
import com.mxpioframework.jpa.query.Criteria;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author: Cheng
 * @date: 2022/10/28
 */
@Service
public class MonitorServerServiceImpl implements IMonitorServerService, JpaUtilAble {

    @Override
    public void afterPropertiesSet(ApplicationContext applicationContext) {

    }

    @Override
    @Transactional(readOnly = false)
    public MonitorServer create(MonitorServer monitorServer) {
        JpaUtil.save(monitorServer);
        return monitorServer;
    }

    @Override
    @Transactional(readOnly = true)
    public Page<MonitorServerVo> queryServerStatus(Criteria criteria, Pageable pageable) {
        String sql = "SELECT\n" +
                "\tS.*,\n" +
                "\tO.OS_NAME,\n" +
                "\tCAST(\n" +
                "\tAVG( 1 - CPU.CPU_IDLE )* 100 AS DECIMAL ( 10, 2 )) AS CPU_USER_PERCENT,\n" +
                "\tCAST(\n" +
                "\tAVG( MEMORY.MEN_USED_PERCENT )* 100 AS DECIMAL ( 10, 2 )) AS MEN_USED_PERCENT,\n" +
                "\tNETCARD.DOWNLOAD_BPS,\n" +
                "\tNETCARD.UPLOAD_BPS,\n" +
                "\tAVERAGE.FIFTEEN AS LOAD_AVERAGE \n" +
                "FROM\n" +
                "\tmi_monitor_server S\n" +
                "\tLEFT JOIN mi_monitor_server_os O ON O.IP = S.IP\n" +
                "\tLEFT JOIN mi_monitor_server_cpu CPU ON CPU.IP = S.IP\n" +
                "\tLEFT JOIN mi_monitor_server_memory MEMORY ON MEMORY.IP = S.IP\n" +
                "\tLEFT JOIN mi_monitor_server_netcard NETCARD ON ( NETCARD.IP = S.IP AND NETCARD.ADDRESS = S.IP )\n" +
                "\tLEFT JOIN mi_monitor_server_load_average AVERAGE ON AVERAGE.IP = S.IP \n" +
                "\tWHERE 1 = 1 " +
                "GROUP BY\n" +
                "\tS.ID,\n" +
                "\tS.IP,\n" +
                "\tS.SERVER_NAME,\n" +
                "\tS.SERVER_SUMMARY,\n" +
                "\tS.IS_ONLINE,\n" +
                "\tS.CONN_FREQUENCY,\n" +
                "\tS.create_time,\n" +
                "\tS.UPDATE_TIME,\n" +
                "\tO.OS_NAME,\n" +
                "\tNETCARD.DOWNLOAD_BPS,\n" +
                "\tNETCARD.UPLOAD_BPS,\n" +
                "\tAVERAGE.FIFTEEN \n" +
                "ORDER BY\n" +
                "\tS.create_time";
        Query query = JpaUtil.nativeQuery(sql, MonitorServerVo.class);
        List<MonitorServerVo> resultList = query.getResultList();
        for (MonitorServerVo serverVo : resultList) {
            // 下行带宽
            String downloadBps = serverVo.getDownloadBps();
            // 上行带宽
            String uploadBps = serverVo.getUploadBps();
            if (StringUtils.isNoneBlank(downloadBps)) {
                String format = DataSizeUtil.format(Double.parseDouble(downloadBps));
                serverVo.setDownloadBps(ZeroOrOneConstants.ZERO.equals(format) ? ZeroOrOneConstants.ZERO : format + "/s");
            }
            if (StringUtils.isNoneBlank(uploadBps)) {
                String format = DataSizeUtil.format(Double.parseDouble(uploadBps));
                serverVo.setUploadBps(ZeroOrOneConstants.ZERO.equals(format) ? ZeroOrOneConstants.ZERO : format + "/s");
            }
        }
        return new PageImpl<>(resultList, pageable, query.getMaxResults());
    }

    @Override
    @Transactional(readOnly = true)
    public Page<MonitorServer> pageServer(Criteria criteria, Pageable pageable) {
        return JpaUtil.linq(MonitorServer.class).where(criteria).paging(pageable);
    }

    @Override
    @Transactional(readOnly = false)
    public void delete(List<String> ids) {
        JpaUtil.lind(MonitorServer.class).in("id", ids).delete();
    }

    @Override
    @Transactional(readOnly = false)
    public void editMonitorServer(MonitorServer monitorServer) {
        JpaUtil.update(monitorServer);
    }

    @Override
    @Transactional(readOnly = false)
    public void dealServerPackage(String msg) {
        ServerPackage serverPackage = JSONObject.parseObject(msg, ServerPackage.class);
        // 把服务器信息添加或更新到数据库
        this.operateServer(serverPackage);
        // 把服务器操作系统信息添加或更新到数据库
        this.operateServerOs(serverPackage);
        // 把服务器内存信息添加或更新到数据库
        this.operateServerMemory(serverPackage);
        // 把服务器内存历史记录添加到数据库
        this.operateServerMemoryHistory(serverPackage);
        // 把服务器CPU信息添加或更新到数据库
        this.operateServerCpu(serverPackage);
        // 把服务器CPU历史记录添加到数据库
        this.operateServerCpuHistory(serverPackage);
        // 把服务器网卡信息添加或更新到数据库
        this.operateServerNetcard(serverPackage);
        // 把服务器网卡历史记录添加到数据库
        this.operateServerNetcardHistory(serverPackage);


    }

    private void operateServer(ServerPackage serverPackage) {
        // IP地址
        String ip = serverPackage.getIp();

        // 查询数据库中是否有此IP的服务器
        boolean exists = JpaUtil.linq(MonitorServer.class)
                .equal("ip", ip)
                .exists();
        if (exists) {
            MonitorServer one = JpaUtil.linq(MonitorServer.class)
                    .equal("ip", ip)
                    .findOne();
            one.setIp(ip);
            one.setServerName(serverPackage.getComputerName());
            one.setConnFrequency((int) serverPackage.getRate());
            one.setUpdateTime(new Date());
            JpaUtil.merge(one);
        } else {
            // 封装对象
            MonitorServer monitorServer = new MonitorServer();
            monitorServer.setId(UUID.randomUUID().toString());
            monitorServer.setIp(ip);
            monitorServer.setServerName(serverPackage.getComputerName());
            monitorServer.setConnFrequency((int) serverPackage.getRate());
            monitorServer.setCreateTime(new Date());
            monitorServer.setOfflineCount(0);
            JpaUtil.persist(monitorServer);
        }
    }

    private void operateServerOs(ServerPackage serverPackage) {
        // 操作系统信息
        OsDomain osDomain = serverPackage.getServer().getOsDomain();
        if (osDomain != null) {
            // IP地址
            String ip = serverPackage.getIp();
            // 查询数据库中是否有此IP的服务器
            boolean exists = JpaUtil.linq(MonitorServerOs.class)
                    .equal("ip", ip)
                    .exists();

            if (exists) {
                MonitorServerOs one = JpaUtil.linq(MonitorServerOs.class)
                        .equal("ip", ip).findOne();
                one.setServerName(osDomain.getComputerName());
                one.setOsName(osDomain.getOsName());
                one.setOsArch(osDomain.getOsArch());
                one.setOsVersion(osDomain.getOsVersion());
                one.setOsTimeZone(osDomain.getOsTimeZone());
                one.setUserHome(osDomain.getUserHome());
                one.setUserName(osDomain.getUserName());
                one.setUpdateTime(serverPackage.getDateTime());
                one.setCreateTime(serverPackage.getDateTime());
                JpaUtil.merge(one);
            } else {
                // 封装对象
                MonitorServerOs monitorServerOs = new MonitorServerOs();
                monitorServerOs.setId(UUID.randomUUID().toString());
                monitorServerOs.setIp(ip);
                monitorServerOs.setServerName(osDomain.getComputerName());
                monitorServerOs.setOsName(osDomain.getOsName());
                monitorServerOs.setOsArch(osDomain.getOsArch());
                monitorServerOs.setOsVersion(osDomain.getOsVersion());
                monitorServerOs.setOsTimeZone(osDomain.getOsTimeZone());
                monitorServerOs.setUserHome(osDomain.getUserHome());
                monitorServerOs.setUserName(osDomain.getUserName());
                monitorServerOs.setUpdateTime(serverPackage.getDateTime());
                JpaUtil.persist(monitorServerOs);
            }
        }
    }

    private void operateServerMemory(ServerPackage serverPackage) {
        // 内存信息
        MemoryDomain memoryDomain = serverPackage.getServer().getMemoryDomain();
        if (memoryDomain != null) {
            // IP地址
            String ip = serverPackage.getIp();
            MemoryDomain.MenDomain menDomain = memoryDomain.getMenDomain();
            MemoryDomain.SwapDomain swapDomain = memoryDomain.getSwapDomain();
            // 判断数据库中是否有此IP的服务器内存
            boolean exists = JpaUtil.linq(MonitorServerMemory.class)
                    .equal("ip", ip)
                    .exists();

            if (exists) {
                MonitorServerMemory one = JpaUtil.linq(MonitorServerMemory.class)
                        .equal("ip", ip)
                        .findOne();
                one.setMemTotal(menDomain.getMemTotal());
                one.setMemUsed(menDomain.getMemUsed());
                one.setMemFree(menDomain.getMemFree());
                one.setMenUsedPercent(menDomain.getMenUsedPercent());
                one.setSwapTotal(swapDomain.getSwapTotal());
                one.setSwapUsed(swapDomain.getSwapUsed());
                one.setSwapFree(swapDomain.getSwapFree());
                one.setSwapUsedPercent(swapDomain.getSwapUsedPercent());
                one.setUpdateTime(serverPackage.getDateTime());
                JpaUtil.merge(one);
            } else {
                // 封装对象
                MonitorServerMemory monitorServerMemory = new MonitorServerMemory();
                monitorServerMemory.setId(UUID.randomUUID().toString());
                monitorServerMemory.setIp(ip);
                monitorServerMemory.setMemTotal(menDomain.getMemTotal());
                monitorServerMemory.setMemUsed(menDomain.getMemUsed());
                monitorServerMemory.setMemFree(menDomain.getMemFree());
                monitorServerMemory.setMenUsedPercent(menDomain.getMenUsedPercent());
                monitorServerMemory.setSwapTotal(swapDomain.getSwapTotal());
                monitorServerMemory.setSwapUsed(swapDomain.getSwapUsed());
                monitorServerMemory.setSwapFree(swapDomain.getSwapFree());
                monitorServerMemory.setSwapUsedPercent(swapDomain.getSwapUsedPercent());
                monitorServerMemory.setCreateTime(serverPackage.getDateTime());
                JpaUtil.persist(monitorServerMemory);
            }
        }
    }

    private void operateServerMemoryHistory(ServerPackage serverPackage) {
        // 内存信息
        MemoryDomain memoryDomain = serverPackage.getServer().getMemoryDomain();
        if (memoryDomain != null) {
            // IP地址
            String ip = serverPackage.getIp();
            MemoryDomain.MenDomain menDomain = memoryDomain.getMenDomain();
            MemoryDomain.SwapDomain swapDomain = memoryDomain.getSwapDomain();
            // 封装对象
            MonitorServerMemoryHistory monitorServerMemoryHistory = new MonitorServerMemoryHistory();
            monitorServerMemoryHistory.setId(UUID.randomUUID().toString());
            monitorServerMemoryHistory.setIp(ip);
            monitorServerMemoryHistory.setMemTotal(menDomain.getMemTotal());
            monitorServerMemoryHistory.setMemUsed(menDomain.getMemUsed());
            monitorServerMemoryHistory.setMemFree(menDomain.getMemFree());
            monitorServerMemoryHistory.setMenUsedPercent(menDomain.getMenUsedPercent());
            monitorServerMemoryHistory.setSwapTotal(swapDomain.getSwapTotal());
            monitorServerMemoryHistory.setSwapUsed(swapDomain.getSwapUsed());
            monitorServerMemoryHistory.setSwapFree(swapDomain.getSwapFree());
            monitorServerMemoryHistory.setSwapUsedPercent(swapDomain.getSwapUsedPercent());
            monitorServerMemoryHistory.setCreateTime(serverPackage.getDateTime());
            monitorServerMemoryHistory.setUpdateTime(serverPackage.getDateTime());
            JpaUtil.persist(monitorServerMemoryHistory);
        }
    }

    private void operateServerCpu(ServerPackage serverPackage) {
        // Cpu信息
        CpuDomain cpuDomain = serverPackage.getServer().getCpuDomain();
        if (cpuDomain != null) {
            // IP地址
            String ip = serverPackage.getIp();
            List<CpuDomain.CpuInfoDomain> cpuInfoDomains = cpuDomain.getCpuList();
            // 要添加的Cpu信息集合
            List<MonitorServerCpu> saveMonitorServerCpus = new ArrayList<>();
            for (int i = 0; i < cpuInfoDomains.size(); i++) {
                CpuDomain.CpuInfoDomain cpuInfoDomain = cpuInfoDomains.get(i);
                // 查询数据库中有没有此IP和此CPU的CPU信息
                boolean exists = JpaUtil.linq(MonitorServerCpu.class)
                        .equal("ip", ip)
                        .equal("cpuNo", i + 1)
                        .exists();

                // 没有
                if (exists) {
                    MonitorServerCpu one = JpaUtil.linq(MonitorServerCpu.class)
                            .equal("ip", ip)
                            .equal("cpuNo", i + 1)
                            .findOne();
                    one.setUpdateTime(serverPackage.getDateTime());
                    JpaUtil.merge(one);
                } else {
                    // 封装对象
                    MonitorServerCpu monitorServerCpu = new MonitorServerCpu();
                    monitorServerCpu.setId(UUID.randomUUID().toString());
                    monitorServerCpu.setIp(ip);
                    monitorServerCpu.setCpuNo(i + 1);
                    monitorServerCpu.setCpuMhz(cpuInfoDomain.getCpuMhz());
                    monitorServerCpu.setCpuVendor(cpuInfoDomain.getCpuVendor());
                    monitorServerCpu.setCpuModel(cpuInfoDomain.getCpuModel());
                    monitorServerCpu.setCpuUser(cpuInfoDomain.getCpuUser());
                    monitorServerCpu.setCpuSys(cpuInfoDomain.getCpuSys());
                    monitorServerCpu.setCpuNice(cpuInfoDomain.getCpuNice());
                    monitorServerCpu.setCpuWait(cpuInfoDomain.getCpuWait());
                    monitorServerCpu.setCpuCombined(cpuInfoDomain.getCpuCombined());
                    monitorServerCpu.setCpuIdle(cpuInfoDomain.getCpuIdle());
                    monitorServerCpu.setCreateTime(serverPackage.getDateTime());
                    saveMonitorServerCpus.add(monitorServerCpu);
                }
            }
            // 有要新增的Cpu
            if (CollectionUtils.isNotEmpty(saveMonitorServerCpus)) {
                JpaUtil.persist(saveMonitorServerCpus);
            }
        }
    }

    private void operateServerCpuHistory(ServerPackage serverPackage) {
        // Cpu信息
        CpuDomain cpuDomain = serverPackage.getServer().getCpuDomain();
        if (cpuDomain != null) {
            // IP地址
            String ip = serverPackage.getIp();
            List<CpuDomain.CpuInfoDomain> cpuInfoDomains = cpuDomain.getCpuList();
            // 要添加的Cpu信息
            List<MonitorServerCpuHistory> saveMonitorServerCpuHistory = new ArrayList<>();
            for (int i = 0; i < cpuInfoDomains.size(); i++) {
                CpuDomain.CpuInfoDomain cpuInfoDomain = cpuInfoDomains.get(i);
                // 封装对象
                MonitorServerCpuHistory monitorServerCpuHistory = new MonitorServerCpuHistory();
                monitorServerCpuHistory.setId(UUID.randomUUID().toString());
                monitorServerCpuHistory.setIp(ip);
                monitorServerCpuHistory.setCpuNo(i + 1);
                monitorServerCpuHistory.setCpuMhz(cpuInfoDomain.getCpuMhz());
                monitorServerCpuHistory.setCpuVendor(cpuInfoDomain.getCpuVendor());
                monitorServerCpuHistory.setCpuModel(cpuInfoDomain.getCpuModel());
                monitorServerCpuHistory.setCpuUser(cpuInfoDomain.getCpuUser());
                monitorServerCpuHistory.setCpuSys(cpuInfoDomain.getCpuSys());
                monitorServerCpuHistory.setCpuNice(cpuInfoDomain.getCpuNice());
                monitorServerCpuHistory.setCpuWait(cpuInfoDomain.getCpuWait());
                monitorServerCpuHistory.setCpuCombined(cpuInfoDomain.getCpuCombined());
                monitorServerCpuHistory.setCpuIdle(cpuInfoDomain.getCpuIdle());
                monitorServerCpuHistory.setCreateTime(serverPackage.getDateTime());
                monitorServerCpuHistory.setUpdateTime(serverPackage.getDateTime());
                saveMonitorServerCpuHistory.add(monitorServerCpuHistory);
            }
            JpaUtil.persist(saveMonitorServerCpuHistory);
        }
    }

    private void operateServerNetcard(ServerPackage serverPackage) {
        // 网卡信息
        NetDomain netDomain = serverPackage.getServer().getNetDomain();
        if (netDomain != null) {
            // IP地址
            String ip = serverPackage.getIp();
            // 设置网卡信息
            List<NetDomain.NetInterfaceDomain> netInterfaceDomains = netDomain.getNetList();
            // 要添加的网卡信息
            List<MonitorServerNetcard> saveMonitorServerNetcard = new ArrayList<>();
            for (int i = 0; i < netInterfaceDomains.size(); i++) {
                NetDomain.NetInterfaceDomain netInterfaceDomain = netInterfaceDomains.get(i);
                // 查询数据库中有没有此IP和网卡的网卡信息
                boolean exists = JpaUtil.linq(MonitorServerNetcard.class)
                        .equal("ip", ip)
                        .equal("netNo", i + 1)
                        .exists();

                // 没有
                if (exists) {
                    MonitorServerNetcard one = JpaUtil.linq(MonitorServerNetcard.class)
                            .equal("ip", ip)
                            .equal("netNo", i + 1)
                            .findOne();
                    // 网卡配置信息
                    one.setAddress(netInterfaceDomain.getAddress());
                    one.setBroadcast(netInterfaceDomain.getBroadcast());
                    one.setMask(netInterfaceDomain.getMask());
                    one.setName(netInterfaceDomain.getName());
                    one.setType(netInterfaceDomain.getType());
                    one.setHwAddr(netInterfaceDomain.getHwAddr());
                    one.setDescription(netInterfaceDomain.getDescription());
                    // 网卡状态信息
                    one.setRxBytes(netInterfaceDomain.getRxBytes());
                    one.setRxDropped(netInterfaceDomain.getRxDropped());
                    one.setRxErrors(netInterfaceDomain.getRxErrors());
                    one.setRxPackets(netInterfaceDomain.getRxPackets());
                    one.setTxBytes(netInterfaceDomain.getTxBytes());
                    one.setTxDropped(netInterfaceDomain.getTxDropped());
                    one.setTxErrors(netInterfaceDomain.getTxErrors());
                    one.setTxPackets(netInterfaceDomain.getTxPackets());
                    // 网速
                    one.setDownloadBps(netInterfaceDomain.getDownloadBps());
                    one.setUploadBps(netInterfaceDomain.getUploadBps());

                    one.setUpdateTime(serverPackage.getDateTime());
                    JpaUtil.merge(one);
                } else {
                    // 封装对象
                    MonitorServerNetcard monitorServerNetcard = new MonitorServerNetcard();
                    monitorServerNetcard.setId(UUID.randomUUID().toString());
                    monitorServerNetcard.setIp(ip);
                    monitorServerNetcard.setNetNo(i + 1);
                    // 网卡配置信息
                    monitorServerNetcard.setAddress(netInterfaceDomain.getAddress());
                    monitorServerNetcard.setBroadcast(netInterfaceDomain.getBroadcast());
                    monitorServerNetcard.setMask(netInterfaceDomain.getMask());
                    monitorServerNetcard.setName(netInterfaceDomain.getName());
                    monitorServerNetcard.setType(netInterfaceDomain.getType());
                    monitorServerNetcard.setHwAddr(netInterfaceDomain.getHwAddr());
                    monitorServerNetcard.setDescription(netInterfaceDomain.getDescription());
                    // 网卡状态信息
                    monitorServerNetcard.setRxBytes(netInterfaceDomain.getRxBytes());
                    monitorServerNetcard.setRxDropped(netInterfaceDomain.getRxDropped());
                    monitorServerNetcard.setRxErrors(netInterfaceDomain.getRxErrors());
                    monitorServerNetcard.setRxPackets(netInterfaceDomain.getRxPackets());
                    monitorServerNetcard.setTxBytes(netInterfaceDomain.getTxBytes());
                    monitorServerNetcard.setTxDropped(netInterfaceDomain.getTxDropped());
                    monitorServerNetcard.setTxErrors(netInterfaceDomain.getTxErrors());
                    monitorServerNetcard.setTxPackets(netInterfaceDomain.getTxPackets());
                    // 网速
                    monitorServerNetcard.setDownloadBps(netInterfaceDomain.getDownloadBps());
                    monitorServerNetcard.setUploadBps(netInterfaceDomain.getUploadBps());
                    monitorServerNetcard.setCreateTime(serverPackage.getDateTime());
                    saveMonitorServerNetcard.add(monitorServerNetcard);
                }
            }
            // 有要添加的网卡信息
            if (CollectionUtils.isNotEmpty(saveMonitorServerNetcard)) {
                JpaUtil.persist(saveMonitorServerNetcard);
            }
        }
    }

    private void operateServerNetcardHistory(ServerPackage serverPackage) {
        // 网卡信息
        NetDomain netDomain = serverPackage.getServer().getNetDomain();
        if (netDomain != null) {
            // IP地址
            String ip = serverPackage.getIp();
            // 设置网卡信息
            List<NetDomain.NetInterfaceDomain> netInterfaceDomains = netDomain.getNetList();
            // 要添加的网卡信息
            List<MonitorServerNetcardHistory> saveMonitorServerNetcardHistory = new ArrayList<>();
            for (int i = 0; i < netInterfaceDomains.size(); i++) {
                NetDomain.NetInterfaceDomain netInterfaceDomain = netInterfaceDomains.get(i);
                // 封装对象
                MonitorServerNetcardHistory monitorServerNetcardHistory = new MonitorServerNetcardHistory();
                monitorServerNetcardHistory.setId(UUID.randomUUID().toString());
                monitorServerNetcardHistory.setIp(ip);
                monitorServerNetcardHistory.setNetNo(i + 1);
                // 网卡配置信息
                monitorServerNetcardHistory.setAddress(netInterfaceDomain.getAddress());
                monitorServerNetcardHistory.setBroadcast(netInterfaceDomain.getBroadcast());
                monitorServerNetcardHistory.setMask(netInterfaceDomain.getMask());
                monitorServerNetcardHistory.setName(netInterfaceDomain.getName());
                monitorServerNetcardHistory.setType(netInterfaceDomain.getType());
                monitorServerNetcardHistory.setHwAddr(netInterfaceDomain.getHwAddr());
                monitorServerNetcardHistory.setDescription(netInterfaceDomain.getDescription());
                // 网卡状态信息
                monitorServerNetcardHistory.setRxBytes(netInterfaceDomain.getRxBytes());
                monitorServerNetcardHistory.setRxDropped(netInterfaceDomain.getRxDropped());
                monitorServerNetcardHistory.setRxErrors(netInterfaceDomain.getRxErrors());
                monitorServerNetcardHistory.setRxPackets(netInterfaceDomain.getRxPackets());
                monitorServerNetcardHistory.setTxBytes(netInterfaceDomain.getTxBytes());
                monitorServerNetcardHistory.setTxDropped(netInterfaceDomain.getTxDropped());
                monitorServerNetcardHistory.setTxErrors(netInterfaceDomain.getTxErrors());
                monitorServerNetcardHistory.setTxPackets(netInterfaceDomain.getTxPackets());
                // 网速
                monitorServerNetcardHistory.setDownloadBps(netInterfaceDomain.getDownloadBps());
                monitorServerNetcardHistory.setUploadBps(netInterfaceDomain.getUploadBps());
                // 时间
                monitorServerNetcardHistory.setCreateTime(serverPackage.getDateTime());
                monitorServerNetcardHistory.setUpdateTime(serverPackage.getDateTime());
                saveMonitorServerNetcardHistory.add(monitorServerNetcardHistory);
            }
            JpaUtil.persist(saveMonitorServerNetcardHistory);
        }
    }
}
